package code._10string._05stringbuffer.demo3;

public class Main {
    public static void main(String[] args) {
        StringBuffer sb = new StringBuffer();
        //容量
        int capacity = sb.capacity();
        System.out.println("capacity = " + capacity);
        
        //长度
        int length = sb.length();
        System.out.println("length = " + length);
        
        //添加
        sb.append("abc");
        System.out.println("sb = " + sb);
        System.out.println("sb.length() = " + sb.length());

        //插入、原有的会自动后移
        sb.insert(1, "yyy");
        System.out.println("sb="+sb);

        //删除
        //public StringBuffer deleteCharAt(int index)：删除指定位置的字符
        sb.deleteCharAt(0);
        System.out.println("sb = " + sb);

        sb.delete(0,3);
        System.out.println("sb = " + sb);

        //替换
        sb.replace(0,1,"xxx");
        System.out.println("sb = " + sb);

        //反转
        StringBuffer sb2 = new StringBuffer("abcd");
        sb2.reverse();
        System.out.println("sb2 = " + sb2);

        //stringBuffer--->string
        String str = sb2.toString();
        System.out.println("str = " + str);
    }
}
